/*    */ package handling.world.family;
/*    */ 
/*    */ import handling.world.WorldFamilyService;
/*    */ import java.util.concurrent.ArrayBlockingQueue;
/*    */ import java.util.concurrent.atomic.AtomicInteger;
/*    */ import org.apache.logging.log4j.LogManager;
/*    */ import org.apache.logging.log4j.Logger;
/*    */ 
/*    */ 
/*    */ 
/*    */ public class FamilyLoad
/*    */ {
/*    */   public static final int NumSavingThreads = 8;
/* 14 */   private static final TimingThread[] Threads = new TimingThread[8];
/* 15 */   private static final Logger log = LogManager.getLogger(FamilyLoad.class);
/* 16 */   private static final AtomicInteger Distribute = new AtomicInteger(0);
/*    */   
/*    */   static {
/* 19 */     for (int i = 0; i < Threads.length; i++) {
/* 20 */       Threads[i] = new TimingThread(new FamilyLoadRunnable());
/*    */     }
/*    */   }
/*    */   
/*    */   public static void QueueFamilyForLoad(int hm) {
/* 25 */     int Current = Distribute.getAndIncrement() % 8;
/* 26 */     Threads[Current].getRunnable().Queue(Integer.valueOf(hm));
/*    */   }
/*    */   
/*    */   public static void Execute(Object ToNotify) {
/* 30 */     for (TimingThread Thread1 : Threads) {
/* 31 */       Thread1.getRunnable().SetToNotify(ToNotify);
/*    */     }
/* 33 */     for (TimingThread Thread : Threads)
/* 34 */       Thread.start(); 
/*    */   }
/*    */   
/*    */   private static class FamilyLoadRunnable
/*    */     implements Runnable
/*    */   {
/* 40 */     private final ArrayBlockingQueue<Integer> Queue = new ArrayBlockingQueue<>(1000);
/*    */     
/*    */     private Object ToNotify;
/*    */     
/*    */     public void run() {
/*    */       try {
/* 46 */         while (!this.Queue.isEmpty()) {
/* 47 */           WorldFamilyService.getInstance().addLoadedFamily(new MapleFamily(((Integer)this.Queue.take()).intValue()));
/*    */         }
/* 49 */         synchronized (this.ToNotify) {
/* 50 */           this.ToNotify.notify();
/*    */         } 
/* 52 */       } catch (InterruptedException ex) {
/* 53 */         FamilyLoad.log.error("[FamilyLoad] 加载学院信息出错." + ex);
/*    */       } 
/*    */     }
/*    */     
/*    */     private void Queue(Integer hm) {
/* 58 */       this.Queue.add(hm);
/*    */     }
/*    */     
/*    */     private void SetToNotify(Object o) {
/* 62 */       if (this.ToNotify == null)
/* 63 */         this.ToNotify = o; 
/*    */     }
/*    */     
/*    */     private FamilyLoadRunnable() {}
/*    */   }
/*    */   
/*    */   private static class TimingThread extends Thread {
/*    */     private final FamilyLoad.FamilyLoadRunnable ext;
/*    */     
/*    */     public TimingThread(FamilyLoad.FamilyLoadRunnable r) {
/* 73 */       super(r);
/* 74 */       this.ext = r;
/*    */     }
/*    */     
/*    */     public FamilyLoad.FamilyLoadRunnable getRunnable() {
/* 78 */       return this.ext;
/*    */     }
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\handling\world\family\FamilyLoad.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */